package edu.whu.webgis.controller;

import edu.whu.webgis.entity.Footprint;
import edu.whu.webgis.mapper.FootprintMapper;
import edu.whu.webgis.service.IFootprintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/footprint")
public class FootprintController {
    @Autowired
    IFootprintService footprintService;
    @GetMapping("/getById")
    public ResponseEntity<List<Footprint>> getFootprintById(@RequestParam String id){
        List<Footprint> footprintList = footprintService.getFootprintById(id);
        if (footprintList != null){
            return ResponseEntity.ok(footprintList);
        }
        else{
            return ResponseEntity.noContent().build();
        }
    }

    @PostMapping("/insert")
    public ResponseEntity<Integer> insertFootprint(@RequestBody Footprint footprint){
        System.out.println("insertFootprint");
        int result = footprintService.insertFootprint(footprint);
        if (result == 1){
            return ResponseEntity.ok(result);
        }
        else{
            return ResponseEntity.badRequest().build();
        }
    }
    @GetMapping("/hf")
    public ResponseEntity<List<String>> getHfProvince(){
        List<String> provinceList = footprintService.getHfProvince();
        if (provinceList.size()!=0){
            return ResponseEntity.ok(provinceList);
        }
        else{
            return ResponseEntity.noContent().build();
        }
    }

    @GetMapping("/cityBaseInfo")
    public ResponseEntity<List<Map<String,Object>>> getCityBase(){
        List<Map<String, Object>> cityBaseInfo = footprintService.getCityBase();
        return ResponseEntity.ok(cityBaseInfo);
    }

    @PostMapping("/test")
    public ResponseEntity<String> test(){
        return ResponseEntity.ok("test");
    }

}
